<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统登录</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <style>
        :root {
            --primary-color: #3498db;
            --secondary-color: #2980b9;
            --light-color: #f8f9fa;
            --dark-color: #343a40;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        .container-login {
            display: flex;
            background-color: white;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            width: 900px;
            max-width: 90%;
            min-height: 500px;
        }

        .container-pic {
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            padding: 2rem;
        }

        .container-pic img {
            max-width: 100%;
            height: auto;
            filter: drop-shadow(0 5px 15px rgba(0, 0, 0, 0.2));
        }

        .login-dialog {
            flex: 1;
            padding: 3rem;
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .login-dialog h3 {
            text-align: center;
            margin-bottom: 2rem;
            color: var(--dark-color);
            font-size: 2rem;
            font-weight: 600;
        }

        .form-group {
            margin-bottom: 1.5rem;
            position: relative;
        }

        .form-group label {
            display: block;
            margin-bottom: 0.5rem;
            color: #555;
            font-weight: 500;
        }

        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 1rem;
            transition: all 0.3s;
        }

        .form-control:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
            outline: none;
        }

        .btn-login {
            width: 100%;
            padding: 12px;
            background-color: var(--primary-color);
            border: none;
            border-radius: 8px;
            color: white;
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s;
            margin-top: 1rem;
        }

        .btn-login:hover {
            background-color: var(--secondary-color);
            transform: translateY(-2px);
        }

        .input-icon {
            position: absolute;
            right: 15px;
            top: 40px;
            color: #aaa;
        }

        @media (max-width: 768px) {
            .container-login {
                flex-direction: column;
                min-height: auto;
            }

            .container-pic {
                padding: 1.5rem;
            }

            .container-pic img {
                max-height: 200px;
            }

            .login-dialog {
                padding: 2rem;
            }
        }
    </style>
</head>

<body>
<div class="container-login">
    <div class="container-pic">
        <img src="pic/computer.png" alt="登录界面插图">
    </div>
    <div class="login-dialog">
        <h3>欢迎登录</h3>
        <div class="form-group">
            <label for="userName"><i class="fas fa-user"></i> 用户名</label>
            <input type="text" name="userName" id="userName" class="form-control" placeholder="请输入用户名">
            <i class="fas fa-check-circle input-icon" id="userName-check" style="display: none;"></i>
        </div>
        <div class="form-group">
            <label for="password"><i class="fas fa-lock"></i> 密码</label>
            <input type="password" name="password" id="password" class="form-control" placeholder="请输入密码">
            <i class="fas fa-eye input-icon" id="togglePassword" style="cursor: pointer;"></i>
        </div>
        <button type="button" class="btn-login" onclick="login()">登 录</button>
    </div>
</div>

<script src="js/jquery.min.js"></script>
<script>
    // 密码可见性切换
    $(document).ready(function() {
        $('#togglePassword').click(function() {
            const password = $('#password');
            const type = password.attr('type') === 'password' ? 'text' : 'password';
            password.attr('type', type);
            $(this).toggleClass('fa-eye fa-eye-slash');
        });

        // 用户名输入验证
        $('#userName').on('input', function() {
            if($(this).val().length > 0) {
                $('#userName-check').show();
            } else {
                $('#userName-check').hide();
            }
        });
    });

    function login() {
        const username = $("#userName").val();
        const password = $("#password").val();

        if(!username || !password) {
            alert("请输入用户名和密码");
            return;
        }

        // 添加加载效果
        $('.btn-login').html('<i class="fas fa-spinner fa-spin"></i> 登录中...').prop('disabled', true);

        $.ajax({
            url: "/user/login",
            type: "post",
            data: {
                username: username,
                password: password,
            },
            success: function(result) {
                if(result == "") {
                    location.href = "book_list.html";
                } else {
                    alert("登录失败: " + result);
                }
            },
            error: function(xhr, status, error) {
                alert("请求出错: " + error);
            },
            complete: function() {
                $('.btn-login').html('登 录').prop('disabled', false);
            }
        });
    }
</script>
</body>

</html>